import {routerData} from '../routes/routerData';
function formatter(data, parentPath = '') {
  const menuList = [];
  data.forEach((item) => {

    if(item.children){
        menuList.push({
        name:item.name,
        icon:item.icon,
        path: `${parentPath}${item.url}`,
        children: formatter(item.children,`${parentPath}${item.url}/`),
      });
    }else{

        if(!routerData[`/${parentPath}${item.url}`]){//前端路由的菜单列表不存在服务端获取的菜单
            console.log('路由页面'+`/${parentPath}${item.url}`+'不存在');
            return menuList;
        }
        routerData[`/${parentPath}${item.url}`].name = item.name;
        menuList.push({
            name:item.name,
            icon:item.icon,
            //path: `${parentPath}${item.url}`,
            path: `${parentPath}${item.url}`,
        });
    }
  });
  return menuList;
}

export const getMenuData = (data) => formatter(data);
